package com.hfb.mashibing.alip8.designpattern._022state;

/**
 * state/Action|open the door|close the door|run the door|stop the door
 * Open        |    ❎       | ✅            |    ❎      |    ❎
 * Closed      |    ✅       |    ❎          |    ❎      |    ❎
 * Running
 * Stopped
 */
public class MainV3 {
    public static void main(String[] args) {
        Car car = new Car();
        car.openTheDoor();
        car.closeTheDoor();
        car.runTheDoor();
        car.stopTheDoor();
    }

    /**
     * 当追加新状态时，非常不方便
     */
    static class Car {
        CarState state = new CarStateImpl();

        public void openTheDoor(){ /* switch case */ state.open(); }
        public void closeTheDoor(){   /* switch case */ state.close(); }
        public void runTheDoor(){   /* switch case */ state.running(); }
        public void stopTheDoor(){   /* switch case */ state.stopped(); }
    }
    static abstract class CarState {
        abstract void open();
        abstract void close();
        abstract void running();
        abstract void stopped();
    }
    static class CarStateImpl extends CarState {
        @Override
        void open() {
            System.out.println("open The Door");
        }

        @Override
        void close() {
            System.out.println("close The Door");
        }

        @Override
        void running() {
            System.out.println("running The car");
        }

        @Override
        void stopped() {
            System.out.println("stopped The car");
        }
    }


}
